package fr.afcepf.atod19.mail;

import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;
import javax.ws.rs.QueryParam;
import javax.activation.*;

/**
 * ATTENTION : NON UTILISE
 * Permet d'envoyer un mail.
 * @author http://www.tutorialspoint.com/java/java_sending_email.htm
 *
 */
public class SendEmail
{
	
	private String senderMail, destMail, subject, mailText;
	
	private String host = "localhost";//"smtp.gmail.com"
	
	
	
	public SendEmail(
			String senderMail,
			String destMail,
			String subject,
			String mailText,
			String host) {
		super();
		this.senderMail = senderMail;
		this.destMail = destMail;
		this.subject = subject;
		this.mailText = mailText;
		this.host = host;
	}



	public static void main(String [] args)
	{    
		// Recipient's email ID needs to be mentioned.
		String to = "abcd@gmail.com";

		// Sender's email ID needs to be mentioned
		String from = "web@gmail.com";

		// Assuming you are sending email from localhost
		String host = "localhost";

		// Get system properties
		Properties properties = System.getProperties();

		// Setup mail server
		properties.setProperty("mail.smtp.host", host);

		// Get the default Session object.
		Session session = Session.getDefaultInstance(properties);

		try{
			// Create a default MimeMessage object.
			MimeMessage message = new MimeMessage(session);

			// Set From: header field of the header.
			message.setFrom(new InternetAddress(from));

			// Set To: header field of the header.
			message.addRecipient(Message.RecipientType.TO,
					new InternetAddress(to));

			// Set Subject: header field
			message.setSubject("This is the Subject Line!");

			// Now set the actual message
			message.setText("This is actual message");

			// Send message
			Transport.send(message);
			System.out.println("Sent message successfully....");
		}catch (MessagingException mex) {
			mex.printStackTrace();
		}
	}
}